﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace ReactiveLang.Util
{
    static class EnumerableUtil
    {
        internal static IEnumerable<T> Defer<T>(Func<IEnumerable<T>> factory)
        {
            foreach(var x in factory())
                yield return x;
        }
        internal static int IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
        {
            Contract.Requires(source != null && predicate != null);
            int index = 0;
            foreach (var item in source)
            {
                if (predicate(item))
                    return index;
                index++;
            }
            return -1;
        }
    }
}
